package com.example.aidlserver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Parcelable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.aidlserver.aidl.Book;


public class MainActivity extends AppCompatActivity   {
    TextView tv_content;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv_content = findViewById(R.id.tv_content);

//        Intent intent = new Intent("remoteserver.addbook");
        IntentFilter intentFilter = new IntentFilter("remoteserver.addbook");
        registerReceiver(new AddBookBroadcastReceiver(),intentFilter);

    }

    class AddBookBroadcastReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            Parcelable parcelable = intent.getParcelableExtra("book");
            if(parcelable!=null){
                Book book = (Book) parcelable;
                tv_content.setText(book.toString());
            }

        }
    }

}
